package com.en.controller;

import com.en.model.Review;
import com.en.response.ErrorCodeMsgEnum;
import com.en.response.R;
import com.en.service.ReviewService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: ReviewWordController
 * Package: com.tencent.wxcloudrun.controller
 * Description:
 *
 * @Date: 2023/11/25 10:07
 * @Author: wht
 */
@Slf4j
@RestController
@RequestMapping("/review")
public class ReviewController {
    @Autowired
    ReviewService reviewService;

    @PutMapping("/add_word")
    public <T> R<T> addWord(@RequestParam(required = true, value = "word_id") Integer word_id) {

        Integer res = reviewService.addWord(word_id);

        if (res == 1) {
            return R.successMsg("");
        } else {
            return R.error(ErrorCodeMsgEnum.SERVICE_ERROR);
        }
    }

    @PatchMapping("/update_review")
    public <T> R<T> updateReview(@RequestParam(required = true, value = "id") Integer id, @RequestParam(required = true, value = "is_right") String is_right) {
        Integer res = reviewService.updateReview(id, is_right);

        if (res == 1) {
            return R.successMsg("");
        } else {
            return R.error(ErrorCodeMsgEnum.SERVICE_ERROR);
        }
    }


    @GetMapping("/get_review")
    public <T> R<T> getReview() {

        List<Review> res = reviewService.getReview();

        return R.successData(res);
    }
}
